package J4_30;

import java.util.*;

public class test {
    public static void main1(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        Map<Integer,Integer> map = new HashMap<>();
        for (int i = 0; i < n; i++) {
            int cur = in.nextInt();
            map.put(cur, map.getOrDefault(cur, 0) + cur);
        }
        int[] f = new int[10001];
        int[] g = new int[10001];
        f[1] = map.getOrDefault(1,0);
        for (int i = 2; i < 10001; i++) {
            f[i] = g[i-1] + map.getOrDefault(i,0);
            g[i] = Math.max(g[i-1], f[i-1]);
        }
        System.out.println(Math.max(f[10000], g[10000]));
    }
    public static void main2(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        List<Integer> list = new ArrayList<>();
        while(in.hasNextInt()) {
            list.add(in.nextInt());
        }
        list.sort((a,b) -> a-b);
        long ret = 0;
        int len = list.size() - 2;
        for (int i = 0; i < n; i++) {
            ret += (long)list.get(len - i * 2);
        }
        System.out.println(ret);

    }
    public static void main3(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int x = (int) Math.sqrt(n);
        int y = x + 1;
        if (n - x*x > y * y - n ) {
            System.out.println(y * y);
        } else {
            System.out.println(x * x);
        }
    }

    public static void main4(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt(), m = in.nextInt();
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < n; i++) {
            int cur = in.nextInt();
            map.put(cur, map.getOrDefault(cur, 0) + 1);
        }
        if (m < map.size()) {
            System.out.println(-1);
            return;
        }
        int maxLen = 0;
        for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
           maxLen = Math.max(maxLen, entry.getValue());
        }
        int l = 1, r = maxLen;
        while (l <= r) {
            int mid = (l + r) / 2;
            int ret = getRet(map, mid);
            if (ret > m) {
                l = mid + 1;
            }else {
                r = mid - 1;
            }
        }
        System.out.println(l);
    }

    private static int getRet(Map<Integer, Integer> map, int mid) {
        int ret = 0;
        for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
            int a = entry.getValue() / mid;
            int b = entry.getValue() % mid;
            ret += a;
            if (b > 0) {
                ret++;
            }
        }
        return ret;
    }

    public static void main5(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt(), m = in.nextInt();
        Map<Integer, List<Integer>> map = new HashMap<>();
        int[] rd = new int[n + 1];
        while(m-- > 0) {
            int x = in.nextInt();
            int y = in.nextInt();
            List<Integer> list = map.getOrDefault(x, new ArrayList<>());
            list.add(y);
            map.put(x, list);
            rd[y]++;
        }
        Queue<Integer> queue = new ArrayDeque<>();
        for (int i = 1; i < n + 1; i++) {
            if (rd[i] == 0) {
                queue.add(i);
            }
        }
        Queue<Integer> ret = new ArrayDeque<>();
        while (!queue.isEmpty()) {
            int a = queue.poll();
            ret.add(a);
            for (int i : map.getOrDefault(a, new ArrayList<>())) {
                rd[i]--;
                if (rd[i] == 0) queue.add(i);
            }
        }
        for (int i = 1; i < n + 1; i++) {
            if (rd[i] != 0) {
                System.out.println(-1);
                return;
            }
        }
        for (int i = 0; i < n; i++) {
            System.out.print(ret.poll());
            if (i != n-1) {
                System.out.print(" ");
            }
        }

    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt(), m = in.nextInt();
        int[] cnt = new int[n + 1];
        Map<Integer, List<Integer>> map = new HashMap<>();
        while (m-- > 0) {
            int x = in.nextInt();
            int y = in.nextInt();
            cnt[y]++;
            if (!map.containsKey(x)) {
                map.put(x, new ArrayList<>());
            }
            map.get(x).add(y);
        }
        Queue<Integer> queue = new ArrayDeque<>();
        for (int i = 1; i <= n; i++) {
            if (cnt[i] == 0) {
                queue.add(i);
            }
        }
        int[] ret = new int[n];
        int pos = 0;
        while (!queue.isEmpty()) {
            int t = queue.poll();
            ret[pos++] = t;
            for (int a : map.getOrDefault(t,new ArrayList<>())) {
                cnt[a]--;
                if (cnt[a] == 0) {
                    queue.add(a);
                }
            }
        }
        if (pos != n) {
            System.out.println(-1);
            return;
        }
        for (int i = 0; i < n; i++) {
            System.out.print(ret[i]);
            if (i != n -1) {
                System.out.print(" ");
            }
        }
    }
}
